package com.guan.friend.test.threalLocalTest;

import com.alibaba.ttl.TransmittableThreadLocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadLocalMain {

    private static ThreadLocal<String> TL = new ThreadLocal<>();
    private static TransmittableThreadLocal<String> TTL = new TransmittableThreadLocal<>();

    public static void main(String[] args) throws Exception {
        TTL.set("parent id");
        ExecutorService executor = Executors.newFixedThreadPool(2);
        executor.submit(() -> {
            // 子线程可以访问父线程的 ThreadLocal 数据
            System.out.println(TTL.get()); // 输出 ParentThreadData
        });
    }
}

